package com.example.smartall.ui;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.smartall.R;
import com.example.smartall.adapter.SplashVpAdapter;
import com.example.smartall.fragment.JobHunting.DeliverHistoryFragment;
import com.example.smartall.fragment.JobHunting.JobHuntingFragment;
import com.example.smartall.fragment.JobHunting.PersonalResumeFragment;
import com.example.smartall.ui.base.BaseActivity;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: abbas
 * @CreateDate: 2022/2/1
 * @Description: 在智慧城市App主页面上的各领域应用服务入口，点击“找工作”图标或信息，进入找工作页面。
 * 找工作功能主要包括找工作、投递记录和个人简历三项功能/导航，点击上方导航栏“返回”按钮返回智慧城市主页面。
 */
public class JobHuntingActivity extends BaseActivity {
    private ImageView imBack;
    private TextView tvTitle;
    private TabLayout tabBar;
    private ViewPager vp;

    private List<Fragment> fragments = new ArrayList<>();
    private SplashVpAdapter vpAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_job_hunting);

        init();
        initData();
        initEvent();
    }

    @Override
    public void init() {
        imBack = (ImageView) findViewById(R.id.im_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tabBar = (TabLayout) findViewById(R.id.tab_bar);
        vp = (ViewPager) findViewById(R.id.vp);

        tvTitle.setText("找工作？没人要...");
    }

    @Override
    public void initEvent() {
        imBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                JobHuntingActivity.this.finish();
            }
        });

        tabBar.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                tabBar.selectTab(tabBar.getTabAt(position));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initData() {
        TabLayout.Tab jobHunting = tabBar.newTab();
        jobHunting.setText("找工作");
        TabLayout.Tab deliverHistory = tabBar.newTab();
        deliverHistory.setText("投递记录");
        TabLayout.Tab personalResume = tabBar.newTab();
        personalResume.setText("个人简历");
        tabBar.addTab(jobHunting);
        tabBar.addTab(deliverHistory);
        tabBar.addTab(personalResume);

        fragments.add(new JobHuntingFragment());
        fragments.add(new DeliverHistoryFragment());
        fragments.add(new PersonalResumeFragment());
        vpAdapter = new SplashVpAdapter(getSupportFragmentManager(), 0, fragments, JobHuntingActivity.this);
        vp.setAdapter(vpAdapter);
    }
}